package org.example.controller.yy;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.models.auth.In;
import org.example.entity.yy.Attractions;
import org.example.entity.yy.Introduce;
import org.example.service.yy.AttractionsService;
import org.example.service.yy.IntroduceService;
import org.example.service.yy.ServiceImpl.AttractionsServiceImpl;
import org.example.utils.Page;
import org.example.utils.Result;
import org.example.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "景点")
@RequestMapping("/yy/jd")
@CrossOrigin
public class AttractionsController {

    @Autowired
    private AttractionsService attractionsService;

    @Autowired
    private AttractionsServiceImpl attractionsServiceImpl;

    @Autowired
    private IntroduceService introduceService;

    //根据传入城市Id查询八个景点
    @RequestMapping("/selectAttractionsByCityId")
    public Result selectAttractionsByCityId(int cityId){
        List<Attractions> list = attractionsService.selectAttractionsByCityId(cityId);
        if (list != null){
            return new  Result<>("200","查询成功",list);
        }else {
            return new  Result<>("400","查询失败",null);
        }
    }

    //根据地点、主题及星级分页查询景点
@RequestMapping("/selectAttractionsByPage")
    public Result selectAttractionsByPage(@RequestParam(value ="start",defaultValue = "1") Integer start,
                                          @RequestParam(value = "pageSize",defaultValue = "8") Integer pageSize,
                                          @RequestParam(value ="address" ) String address,
                                          @RequestParam(value ="topic" ) String topic,
                                          @RequestParam(value = "star" ) String star,
                                          @RequestParam(value = "attName" ) String attName){
        PageInfo<Attractions> pageInfo = attractionsServiceImpl.selectAttractionsByPage(start, pageSize,Math.toIntExact(ThreadLocalUtil.getCurrentId()), address, topic, star,attName);
        if (pageInfo != null) {
            return new Result<>("200", "查询成功", pageInfo);
        }else {
            return new Result<>("400", "查询失败", null);
        }
    }

    //根据景点id查询景点详情
    @RequestMapping("/selectAttractionsById")
    public Result selectAttractionsById(@RequestParam(value = "id") Integer attId){
        List<Introduce> list = introduceService.selectByScenicId(attId);
        Attractions attractions = attractionsService.selectAttractionsById(attId);
        attractions.setLists(list);
        if (attractions != null){
            return new  Result<>("200","查询成功",attractions);
        }else {
            return new  Result<>("400","查询失败",null);
        }
    }

    //根据景点id修改浏览量
    @RequestMapping("/updateViewsById")
    public Result updateViewsById(@RequestParam(value = "id") Integer attId){
        Integer integer = attractionsService.updateViewsById(attId);
        if (integer != null){
            return new  Result<>("200","修改成功",integer);
        }else {
            return new  Result<>("400","修改失败",null);
        }
    }
}
